package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AvLocal;
import com.ruoyi.system.service.IAvLocalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 本地文件Controller
 * 
 * @author ruoyi
 * @date 2021-03-16
 */
@Controller
@RequestMapping("/system/local")
public class AvLocalController extends BaseController
{
    private String prefix = "system/local";

    @Autowired
    private IAvLocalService avLocalService;

    @RequiresPermissions("system:local:view")
    @GetMapping()
    public String local()
    {
        return prefix + "/local";
    }

    /**
     * 查询本地文件列表
     */
    @RequiresPermissions("system:local:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AvLocal avLocal)
    {
        startPage();
        List<AvLocal> list = avLocalService.selectAvLocalList(avLocal);
        return getDataTable(list);
    }

    /**
     * 导出本地文件列表
     */
    @RequiresPermissions("system:local:export")
    @Log(title = "本地文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AvLocal avLocal)
    {
        List<AvLocal> list = avLocalService.selectAvLocalList(avLocal);
        ExcelUtil<AvLocal> util = new ExcelUtil<AvLocal>(AvLocal.class);
        return util.exportExcel(list, "local");
    }

    /**
     * 新增本地文件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存本地文件
     */
    @RequiresPermissions("system:local:add")
    @Log(title = "本地文件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AvLocal avLocal)
    {
        return toAjax(avLocalService.insertAvLocal(avLocal));
    }

    /**
     * 修改本地文件
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AvLocal avLocal = avLocalService.selectAvLocalById(id);
        mmap.put("avLocal", avLocal);
        return prefix + "/edit";
    }

    /**
     * 修改保存本地文件
     */
    @RequiresPermissions("system:local:edit")
    @Log(title = "本地文件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AvLocal avLocal)
    {
        return toAjax(avLocalService.updateAvLocal(avLocal));
    }

    /**
     * 删除本地文件
     */
    @RequiresPermissions("system:local:remove")
    @Log(title = "本地文件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(avLocalService.deleteAvLocalByIds(ids));
    }

    /**
     * 本地文件生成入库
     * @return
     */
    @Log(title = "本地文件", businessType = BusinessType.INSERT)
    @PostMapping( "/gen")
    @ResponseBody
    public AjaxResult gen(String url){return toAjax(avLocalService.gen(url));}
}
